import tables
import datetime
from html import Link
from google.appengine.ext import db

def setup():
    #Times 
    tables.Time(key_name = 'Admin Setup', name = 'Admin Setup').put()             #first time - admin set up
    tables.Time(key_name = 'Ta Apply', name = 'Ta Apply').put()                 #second time - ta's apply
    tables.Time(key_name = 'Instructor Apply', name = 'Instructor Apply').put() #third time - instructors apply
    tables.Time(key_name = 'Admin Match', name = 'Admin Match').put()           #fourth time - admins match tas to secionts

    #Seasons
    fall = tables.Season(key_name='fall', name = 'fall')
    spring = tables.Season(key_name='spring', name = 'spring')
    summer = tables.Season(key_name='summer', name = 'summer')
    fall.put()
    spring.put()
    summer.put()
    
    #Semesters
    spring2009 = tables.Semester(key_name = 'spring2009', season = tables.Season.get_by_key_name('spring'), year = 2009) # had to define here so could use in appstate
    spring2009.put()
    fall2008 = tables.Semester(key_name = "fall2008", season = fall, year = 2008)    
    fall2008.put()
    spring2008 = tables.Semester(key_name = "spring2008", season = spring, year = 2008)
    spring2008.put()
    
    #setting currentState
    tables.AppState(key_name = 'currentState', semester = spring2009, time = tables.Time.get_by_key_name('Admin Setup')).put()    
    
    #Courses
    cs341 = tables.Course(name = "Automata Theory", identifier = "CS341")
    cs341.put()
    cs313k = tables.Course(name = "Logic, Sets, and Functions", identifier = "CS313k")
    cs313k.put()
    cs357h = tables.Course(name = "Algorithms: Honors", identifier = "CS374H")
    cs357h.put()
    cs361 = tables.Course(name = "Introduction to Computer Security", identifier = "CS361")
    cs361.put()
    cs367 = tables.Course(name = "Numerical Methods", identifier = "CS367")
    cs367.put()
    cs369 = tables.Course(name = "Systems Modeling I", identifier = "CS369")
    cs369.put()
    cs371p = tables.Course(name = "Object-Oriented Programming", identifier = "CS371P")
    cs371p.put()
    cs371r = tables.Course(name = "Information Retrieval and Web Search", identifier = "CS371R")
    cs371r.put()
    cs373 = tables.Course(name = "Software Engineering", identifier = "CS373")
    cs373.put()
    cs378 = tables.Course(name = "Computational Brain-W", identifier = "CS378")
    cs378.put()
    cs307 = tables.Course(name = "Foundations of Computer Science", identifier = "CS307")
    cs307.put()
    cs315 = tables.Course(name = "Algorithms and Data Structures", identifier = "CS315")
    cs315.put()
    cs345 = tables.Course(name = "Programming Languages", identifier = "CS345")
    cs345.put()    
    cs310 = tables.Course(name = "Computer Organization", identifier = "CS310")
    cs310.put()
    cs372 = tables.Course(name = "Intro to Operating Systems", identifier = "CS372")
    cs372.put()
    cs336 = tables.Course(name = "Analysis of Programs", identifier = "CS336")
    cs336.put()
    cs302 = tables.Course(name = "Computer Fluency", identifier = "CS302")
    cs302.put()

    #Instructors
    i1 = tables.Instructor(firstName = "Vicki", lastName = "Almstrum", eid = 'va223')
    i1.put()
    i2 = tables.Instructor(firstName = "Dana", lastName = "Ballard", eid = 'db223')
    i2.put()
    i3 = tables.Instructor(firstName = "Glenn", lastName = "Downing", eid = 'gd223')
    i3.put()
    i4 = tables.Instructor(firstName = "Ray", lastName = "Mooney", eid = 'rm223')
    i4.put()
    i5 = tables.Instructor(firstName = "Vijaya", lastName = "Ramachandran", eid = 'vr223')
    i5.put()
    i6 = tables.Instructor(firstName = "William", lastName = "Young", eid = 'wy223')
    i6.put()
    i7 = tables.Instructor(firstName = "Lorenzo", lastName = "Alvisi", eid = 'la223')
    i7.put()
    i8 = tables.Instructor(firstName = "Vicki", lastName = "Almstrum", eid = 'va224')
    i8.put()
    i9 = tables.Instructor(firstName = "Don", lastName = "Fussell", eid = 'df223')
    i9.put()
    i10 = tables.Instructor(firstName = "Mohamed", lastName = "Gouda", eid = 'mg223')
    i10.put()

    #Sections
    tables.Section(course = cs373, uniqueNumber = 54625, semester = spring2009, numTas = 1, numStudents = 30, instructor = i3 ).put()
    tables.Section(course = cs373, uniqueNumber = 54270, semester = spring2009, numTas = 1, numStudents = 30, instructor = i3 ).put()
    tables.Section(course = cs378, uniqueNumber = 54285, semester = spring2009, numTas = 1, numStudents = 30, instructor = i2 ).put()
    tables.Section(course = cs361, uniqueNumber = 54230, semester = spring2009, numTas = 2, numStudents = 40, instructor = i6 ).put()
    tables.Section(course = cs357h, uniqueNumber = 54225, semester = spring2009, numTas = 1, numStudents = 15, instructor = i5 ).put()
    tables.Section(course = cs371p, uniqueNumber = 55735, semester = fall2008, numTas = 1, numStudents = 50, instructor = i5 ).put()
    tables.Section(course = cs373, uniqueNumber = 55754, semester = fall2008, numTas = 2, numStudents = 60, instructor = i5 ).put()
    tables.Section(course = cs378, uniqueNumber = 55750, semester = spring2008, numTas = 1, numStudents = 30, instructor = i2 ).put()
    tables.Section(course = cs371r, uniqueNumber = 55720, semester = spring2008, numTas = 1, numStudents = 25, instructor = i4 ).put()
    tables.Section(course = cs373, uniqueNumber = 55740, semester = spring2008, numTas = 1, numStudents = 25, instructor = i8 ).put()

    #Majors
    computerScience = tables.Major(name = 'Computer Science')
    computerScience.put()
    computerEngineering = tables.Major(name = 'Computer Engineering')
    computerEngineering.put()
    electricEngineering = tables.Major(name = 'Electric Engineering')
    electricEngineering.put()
    
    #Specializations
    softwareEngineering = tables.Specialization(name = 'Software Engineering')
    softwareEngineering.put()
    os = tables.Specialization(name = 'Operating Systems')
    os.put()
    computerVision = tables.Specialization(name = 'Computer Vision')
    computerVision.put()
    natLangProc = tables.Specialization(name = 'Natural Language Processing')
    natLangProc.put()
    parallelComputing = tables.Specialization(name = 'Parallel Computing')
    parallelComputing.put()
    vlsiDesign = tables.Specialization(name = 'Microprocessor and VLSI Design')
    vlsiDesign.put()
    theory = tables.Specialization(name = 'Theory')
    theory.put()
    graphics = tables.Specialization(name = 'Graphics')
    graphics.put()
    networking = tables.Specialization(name = 'Networking')
    networking.put()
    
    #Languages
    java = tables.Language(name = "Java")
    java.put()
    python = tables.Language(name = "Python")
    python.put()
    c = tables.Language(name = "C")
    c.put()
    cpp = tables.Language(name = "C++")
    cpp.put()
    pascal = tables.Language(name = "Pascal")
    pascal.put()
    lisp = tables.Language(name = "Lisp")
    lisp.put()
    ruby = tables.Language(name = "Ruby")
    ruby.put()
    perl = tables.Language(name = "Perl")
    perl.put()
    assembly = tables.Language(name = "Assembly")
    assembly.put()
    visualBasic = tables.Language(name = "Visual Basic")
    visualBasic.put()

    #tas
    ta1 = tables.Ta(
        firstName = "Steven", lastName = "Baggs", 
        phone = '5122329385',
        email = 'bags@cs.utexas.edu',
        major = computerScience, 
        admissionDate = datetime.date(2008,9,1), 
        degree = 'PhD', 
        supervisor = "Glenn Downing", 
        residency = True, #true if citizen
        nativeEnglish = True, 
        semester = spring2009,
        eid = 'sb123',
        submitted = True)
    ta1.put()
    for course in [cs307, cs315, cs373]: tables.TaTaHistory(taHistory = course, ta = ta1).put()
    for course in [cs373, cs361]: tables.TaQualification(qualification = course, ta = ta1).put()
    for language in [java,python]: tables.TaLanguage(language = language, ta = ta1).put()
    for area in [softwareEngineering]: tables.TaSpecialization(specialization = area, ta = ta1).put()

    ta2 = tables.Ta(
        firstName = "Jessica", lastName = "Higgins", 
        phone = '5123459582',
        email = 'JH@cs.utexas.edu',
        major = computerScience, 
        admissionDate = datetime.date(2006,9,1), 
        degree = 'PhD', 
        supervisor = "Lorenzo Alvisi", 
        residency = True, 
        nativeEnglish = True, 
        semester = spring2009,
        eid = 'jh123',
        submitted = True)
    ta2.put()
    for course in [cs307, cs345]: tables.TaTaHistory(taHistory = course, ta = ta2).put()
    for course in [cs307, cs315]: tables.TaQualification(qualification = course, ta = ta2).put()
    for language in [c, cpp, java]: tables.TaLanguage(language = language, ta = ta2).put()
    for area in [os]: tables.TaSpecialization(specialization = area, ta = ta2).put()

    ta3 = tables.Ta(
        firstName = "Bob", lastName = "Mathews", 
        phone = '4088499278',
        email = 'bobm@cs.utexas.edu',
        major = computerScience, 
        admissionDate = datetime.date(2007,6,2), 
        degree = 'Masters', 
        supervisor = "Dana Ballard", 
        residency = True, 
        nativeEnglish = True, 
        semester = spring2009,
        eid = 'bm123',
        submitted = True)
    ta3.put()
    for course in [cs302, cs310, cs373]: tables.TaTaHistory(taHistory = course, ta = ta3).put()
    for course in [cs313k, cs378, cs371r]: tables.TaQualification(qualification = course, ta = ta3).put()
    for language in [lisp, java, pascal]: tables.TaLanguage(language = language, ta = ta3).put()
    for area in [computerVision]: tables.TaSpecialization(specialization = area, ta = ta3).put()

    ta4 = tables.Ta(
        firstName = "Ahmadi", lastName = "Alagappan", 
        phone = '5127893709',
        email = 'aapan@hotmail.com',
        major = computerScience, 
        admissionDate = datetime.date(2004,9,20), 
        degree = 'PhD', 
        supervisor = "Ray Mooney", 
        residency = False, 
        nativeEnglish = False, 
        semester = spring2009,
        eid = 'aa123',
        submitted = True)
    ta4.put()
    for course in [cs315, cs357h, cs371r]: tables.TaTaHistory(taHistory = course, ta = ta4).put()
    for course in [cs315, cs336, cs357h, cs361]: tables.TaQualification(qualification = course, ta = ta4).put()
    for language in [lisp, cpp]: tables.TaLanguage(language = language, ta = ta4).put()
    for area in [natLangProc]: tables.TaSpecialization(specialization = area, ta = ta4).put()

    ta5 = tables.Ta(
        firstName = "Henry", lastName = "Huntington", 
        phone = '2029680988',
        email = 'goodhunt@gmail.com',
        major = computerScience, 
        admissionDate = datetime.date(2008,9,1), 
        degree = 'PhD', 
        supervisor = "Glenn Downing", 
        residency = True, 
        nativeEnglish = True, 
        semester = spring2009,
        eid = 'hh123',
        submitted = True)
    ta5.put()
    for course in []: tables.TaTaHistory(taHistory = course, ta = ta5).put()
    for course in [cs302]: tables.TaQualification(qualification = course, ta = ta5).put()
    for language in [ruby, perl, python]: tables.TaLanguage(language = language, ta = ta5).put()
    for area in [parallelComputing]: tables.TaSpecialization(specialization = area, ta = ta5).put()

    ta6 = tables.Ta(
        firstName = "Adriana", lastName = "Kit", 
        phone = '4152969782',
        email = 'akit@cs.utexas.edu',
        major = computerScience, 
        admissionDate = datetime.date(2009,1,20), 
        degree = 'Masters', 
        #no supervisor
        residency = False, 
        nativeEnglish = False, 
        semester = spring2009,
        eid = 'ak123',
        submitted = True)
    ta6.put()
    for course in []: tables.TaTaHistory(taHistory = course, ta = ta6).put()
    for course in [cs373]: tables.TaQualification(qualification = course, ta = ta6).put()
    for language in [java, ruby]: tables.TaLanguage(language = language, ta = ta6).put()
    for area in []: tables.TaSpecialization(specialization = area, ta = ta6).put() # no specializations

    ta7 = tables.Ta(
        firstName = "Nancy", lastName = "Liu", 
        phone = '5129680294',
        email = 'liun@cs.utexas.edu',
        major = electricEngineering, 
        admissionDate = datetime.date(2002,9,1), 
        degree = 'PhD', 
        supervisor = "Doug Burger", 
        residency = False, 
        nativeEnglish = False, 
        semester = spring2009,
        eid = 'nl123',
        submitted = True)
    ta7.put()
    for course in [cs372]: tables.TaTaHistory(taHistory = course, ta = ta7).put()
    for course in [cs372, cs367]: tables.TaQualification(qualification = course, ta = ta7).put()
    for language in [c, assembly]: tables.TaLanguage(language = language, ta = ta7).put()
    for area in [vlsiDesign]: tables.TaSpecialization(specialization = area, ta = ta7).put()

    ta8 = tables.Ta(
        firstName = "Gupta", lastName = "Kumar", 
        phone = '5105641205',
        email = 'gk@yahoo.com',
        major = computerScience, 
        admissionDate = datetime.date(2008,9,1), 
        degree = 'Masters', 
        supervisor = "Vijaya Ramachandran", 
        residency = False, 
        nativeEnglish = False, 
        semester = spring2009,
        eid = 'gk123',
        submitted = True)
    ta8.put()
    for course in [cs371p]: tables.TaTaHistory(taHistory = course, ta = ta8).put()
    for course in [cs341, cs367]: tables.TaQualification(qualification = course, ta = ta8).put()
    for language in [c, python, java]: tables.TaLanguage(language = language, ta = ta8).put()
    for area in [theory]: tables.TaSpecialization(specialization = area, ta = ta8).put()

    ta9 = tables.Ta(
        firstName = "Paolo", lastName = "Giovanni", 
        phone = '5121012492',
        email = 'pg13@cs.utexas.edu',
        major = computerScience, 
        admissionDate = datetime.date(2003,1,20), 
        degree = 'PhD', 
        supervisor = "Don Fussell", 
        residency = False, 
        nativeEnglish = False, 
        semester = spring2009,
        eid = 'pg123',
        submitted = True)
    ta9.put()
    for course in [cs315, cs336]: tables.TaTaHistory(taHistory = course, ta = ta9).put()
    for course in [cs373, cs361]: tables.TaQualification(qualification = course, ta = ta9).put()
    for language in [c, java, perl]: tables.TaLanguage(language = language, ta = ta9).put()
    for area in [graphics]: tables.TaSpecialization(specialization = area, ta = ta9).put()

    ta10 = tables.Ta(
        firstName = "Mona", lastName = "Liz", 
        phone = '5121294658',
        email = 'moonlit@hotmai.com', #probably a typo
        major = computerScience, 
        admissionDate = datetime.date(2000,9,1), 
        degree = 'PhD', 
        supervisor = "Mohamed Gouda", 
        residency = True, 
        nativeEnglish = True, 
        semester = spring2009,
        eid = 'ml123',
        submitted = True)
    ta10.put()
    for course in [cs302, cs307, cs361, cs371p]: tables.TaTaHistory(taHistory = course, ta = ta10).put()
    for course in []: tables.TaQualification(qualification = course, ta = ta10).put() #no qualifications
    for language in [visualBasic]: tables.TaLanguage(language = language, ta = ta10).put()
    for area in [networking]: tables.TaSpecialization(specialization = area, ta = ta10).put()

allLinks = [
    Link('/login', 'Login'),
    Link('/ta', 'TA Application'),
    Link('/instructor', 'Instructor Application'),
    Link('/admin', 'Admin Setup'),
    Link('/admin/match', 'Admin Match'),
    Link('/admin/advSearch', 'Admin Advanced Search'),
    Link('/admin/quickSearch', 'Admin Quick Search'),
    Link('/webTest', 'Unit Tests'),
    ]
    
#2 attributes defining current state of app - time and semester
if tables.AppState.get_by_key_name('currentState') == None: #only want to set if not already set
    setup()

    
def notTimeStr(verb):
    return 'Sorry, its not the right time for %s. (Note to grader: The time is set in the Admin Setup page.)' % verb
